class ProveedoresController < ApplicationController
	before_filter :login_required
  # GET /proveedores
  # GET /proveedores.xml
  def index
    @proveedores = Proveedor.find(:all).reverse

    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @proveedores.to_xml }
    end
  end
  
  def search  	
    @proveedores = Proveedor.search(params[:key], params[:lugar_id]).reverse    
    respond_to do |format|
      format.html { render :action => 'index' }
      format.xml  { render :xml => @proveedores.to_xml }
    end    
  end

  # GET /proveedores/1
  # GET /proveedores/1.xml
  def show
    @proveedor = Proveedor.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @proveedor.to_xml }
    end
  end

  # GET /proveedores/new
  def new
    @proveedor = Proveedor.new
  end

  # GET /proveedores/1;edit
  def edit
    @proveedor = Proveedor.find(params[:id])
  end

  # POST /proveedores
  # POST /proveedores.xml
  def create
    @proveedor = Proveedor.new(params[:proveedor])

    respond_to do |format|
      if @proveedor.save
        flash[:notice] = 'Proveedor was successfully created.'
        format.html { redirect_to proveedor_url(@proveedor) }
        format.xml  { head :created, :location => proveedor_url(@proveedor) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @proveedor.errors.to_xml }
      end
    end
  end

  # PUT /proveedores/1
  # PUT /proveedores/1.xml
  def update
    @proveedor = Proveedor.find(params[:id])

    respond_to do |format|
      if @proveedor.update_attributes(params[:proveedor])
        flash[:notice] = 'Proveedor was successfully updated.'
        format.html { redirect_to proveedor_url(@proveedor) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @proveedor.errors.to_xml }
      end
    end
  end

  # DELETE /proveedores/1
  # DELETE /proveedores/1.xml
  def destroy
    @proveedor = Proveedor.find(params[:id])
    @proveedor.destroy

    respond_to do |format|
      format.html { redirect_to proveedores_url }
      format.xml  { head :ok }
    end
  end
end
